<?php

namespace App\Http\Controllers;

use App\Traits\Templates\FrontTemplate;
use App\Traits\Templates\KitchenTemplate;
use App\Traits\Templates\WaterTemplate;
use Illuminate\Http\Request;

class PrintController extends Controller
{
	use FrontTemplate;
	use KitchenTemplate;
	use WaterTemplate;

    public function print(Request $request)
    {
    	// $content = $this->FrontContent($this->frontData);
    	$content = $this->KitchenOrderTemplate($this->kitchenOrderDate);
        // $content = $this->KitchenSingleTemplate($this->kitchenSingleData);
        // $content = $this->WaterOrderTemplate($this->waterOrderData);
        // $content = $this->WaterSingleTemplate($this->waterSingleData);
    	// dd($content);
        $m1 = '4004670883';
        $m2 = '4004703777';
    	$res = $this->cell_print($m2, $content);
    }

    public function cell_print($machine,$content)
    {
        $url="http://dev-ktvprint.ffun360.com/yilianyun?machine_id=".$machine."&contents=".urlencode($content);

        $this->httpGet($url);
    }
    
    public function httpGet($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}
